﻿using Himp.TaskScheduling.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace Himp.TaskScheduling
{
    /// <summary>
    /// 设备启停控制
    /// </summary>
    public class CmDeviceControlService : TaskSchedulingAppService, ICmDeviceControlService
    {
        private IRepository<CmDeviceControl, int> _cmDeviceControlRepository;

        public CmDeviceControlService(IRepository<CmDeviceControl, int> cmDeviceControlRepository)
        {
            _cmDeviceControlRepository = cmDeviceControlRepository;
        }

        public async Task<CmDeviceControlDto> GetAsync(int id)
        { 
            var cmDeviceControl = await _cmDeviceControlRepository.GetAsync(id);
            var itemDto = ObjectMapper.Map<CmDeviceControl, CmDeviceControlDto>(cmDeviceControl);

            return itemDto;
        }

        public async Task<CmDeviceControlDto> PutAsync(int id, CmDeviceControlUpdateDto input)
        {
            var cmDeviceControl = await _cmDeviceControlRepository.GetAsync(id);
            cmDeviceControl.ENABLE = input.Enable;
            cmDeviceControl = await _cmDeviceControlRepository.UpdateAsync(cmDeviceControl);
            var itemDto = ObjectMapper.Map<CmDeviceControl, CmDeviceControlDto>(cmDeviceControl);

            return itemDto;
        }
    }
}
